//
//  UseData.m
//  QuickCure
//
//  Created by MootYue on 16/5/6.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "UserData.h"


@implementation UserData

//单例创建
+(instancetype)sharedInstance{
    static UserData *use = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        use = [UserData new];
    });
    
    return use;
}

-(UserData *)setDataFromDict:(NSDictionary *)dict{
    
    UserData *data = [UserData sharedInstance];
 
    [data yy_modelSetWithDictionary:dict];
 
    return data;
}


//保存用户信息
-(void)saveUserInfoSanBox:(UserData *)userData{
    
    NSUserDefaults *defult = [NSUserDefaults standardUserDefaults];
    [defult setObject:userData.user_id forKey:@"user_id"];
    [defult setObject:userData.true_name forKey:@"true_name"];
    [defult setObject:userData.card_number forKey:@"card_number"];
    [defult setObject:userData.height forKey:@"userHeight"];
    [defult setObject:userData.weight forKey:@"usetWeight"];
    [defult setObject:userData.address forKey:@"userProvince"];
    [defult setObject:userData.mobile_number forKey:@"mobile_number"];
    [defult setObject:userData.head_photo forKey:@"head_photo"];
    
    [defult synchronize];
}

//加载用户信息
-(void)loadUserInfoFromSanBox{
    NSUserDefaults *defult = [NSUserDefaults standardUserDefaults];
    self.user_id = [defult objectForKey:@"user_id"];
    self.true_name = [defult objectForKey:@"true_name"];
    self.card_number = [defult objectForKey:@"card_number"];
    self.height = [defult objectForKey:@"userHeight"];
    self.weight = [defult objectForKey:@"usetWeight"];
    self.address = [defult objectForKey:@"userProvince"];
    self.mobile_number = [defult objectForKey:@"mobile_number"];
    self.head_photo = [defult objectForKey:@"head_photo"];
    
}

-(void)cleanUserInfo{
    NSUserDefaults *defult = [NSUserDefaults standardUserDefaults];
    //移除相应的值
    [defult removeObjectForKey:@"user_id"];
    [defult removeObjectForKey:@"true_name"];
    [defult removeObjectForKey:@"card_number"];
    //赋为初始值@“”
    self.user_id = @"";
    self.true_name = @"";
    self.card_number = @"";
}


@end
